package com.cy.pj.sys.pojo.web.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.pojo.SysLog;
import com.cy.pj.sys.pojo.service.SysLogservice;
import com.cy.pj.sys.pojo.web.pojo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * restful 风格url(一种编码风格)
 * GetMapping 所有-->/log/
 * GetMapping 某个-->/log/{id}
 * DeleteMapping 某些-->/log/{id}
 */

@RequestMapping("/log/")
@RestController
public class SysLogController {
    @Autowired
    private SysLogservice sysLogservice;
    //删除
    @DeleteMapping("doDeleteById/{ids}")
    public  JsonResult doDeleteById(Long...ids){
        sysLogservice.deleteById(ids);
        return new JsonResult("删除成功");
    }

    //通过ID查询
    @GetMapping("doFindById/{id}")
    public  JsonResult doFindById(@PathVariable Long  id){
        return new JsonResult(sysLogservice.findById(id));
    }
   //查询日志
    //GetMapper不加路径的话就是查所有如访问路径是:(localhost/log/)这是属于rest风格
    @GetMapping("doFindLogs")
    public JsonResult doFindLogs(SysLog sysLog) {
        //lamba表达式
        return new JsonResult(
                PageUtil.startPage().doSelectPageInfo(()->
                        sysLogservice.findLogs(sysLog)
    ));
    }
        // 封装查询结果                 1. 启动分页拦截        2.执行查询信息/信息的拦截
//        return new JsonResult( PageUtil.startPage().doSelectPageInfo(new ISelect() {
//            @Override
//            public void doSelect() {
                          //3.
//                sysLogservice.findLogs(sysLog);
//            }
//        }));

    }



